import type { LoginFormData, RegisterFormData, User } from './type'
import request from '@/utils/request'

enum API {
  REGISTER = '/sysUser/register',
  LOGIN = '/sysUser/login',
  LOGINOUT = '/sysUser/logout',
  PAGE = '/sysUser/page',
  ADD = '/sysUser/add',
  UPDATE = '/sysUser/update',
}

export const register = (data: RegisterFormData) => request.post(API.REGISTER, data)
export const login = (data: LoginFormData) => request.post(API.LOGIN, data)
export const logout = () => request.post(API.LOGINOUT)

export function userPage(data: User) {
  return request<any, PageResult<User[]>>({
    url: API.PAGE,
    method: 'post',
    data,
  })
}

export function addUser(data: User) {
  return request<string>({
    url: API.ADD,
    method: 'post',
    data,
  })
}

export function updateUser(data: User) {
  return request<string>({
    url: API.UPDATE,
    method: 'post',
    data,
  })
}
